package com.pinguix.games.pong;

import danger.app.Application;
import danger.app.Event;
import danger.app.Timer;

public class Pong extends Application
{
	private PongWindow _window;
	private static Timer _frameTimer;
	private static boolean _paused = false;
	
	private static Application _instance;
	
	public Pong()
	{
		_instance = this;
		_window = new PongWindow();
		_window.setTitle("Pong");
		PongAudio.setup();
	}
	public static Application getInstance()
	{
		return _instance;
	}
	public void resume()
	{
		// 100 is 10 frames per second
		// 150 is 7.5 frames per second
		// 200 is 5 frames per second
		if(_frameTimer == null)
		{
			_frameTimer = new Timer(75, true, this);
		}
		unpause();
		_window.show();
		PongAudio.setup();
	}
	public void suspend()
	{
		pause();
		updatePreviewScreen();
		PongAudio.cleanup();
	}
	public static void pause()
	{
		_paused = true;
		if(_frameTimer != null)
		{
			_frameTimer.stop();
		}
	}
	public static void unpause()
	{
		_paused = false;
		_frameTimer.start();
	}
	
	public static boolean isPaused()
	{
		return _paused;
	}
	public boolean receiveEvent(Event e)
	{
		switch(e.type)
		{
			case Event.EVENT_TIMER:
				_window.update();
				break;
		}
		return (super.receiveEvent(e));
	}
	
}
